<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        document.addEventListener('keyup', function(e) {
            console.log('up:' + e.keyCode);
            //利用keyCode返回的ASCII码来判断用户按下了哪个键
            if (e.keyCode === 65) {
                alert('您按下的是a键！');
            } else {
                alert('您没有按下a键!');
            }
        });
        document.addEventListener('keypress', function(e) {
            console.log('press:' + e.keyCode);
        });
    </script>
</body>

</html>